namespace OdeToFoo.Migrations
{
    using OdeToFoo.Models;
    using System;
    using System.Collections.Generic;
    using System.Data.Entity;
    using System.Data.Entity.Migrations;
    using System.Linq;

    internal sealed class Configuration : DbMigrationsConfiguration<OdeToFoo.Models.OdeToFooDb>
    {
        public Configuration()
        {

            AutomaticMigrationsEnabled = true;
            AutomaticMigrationDataLossAllowed = true;
        }

        protected override void Seed(OdeToFoo.Models.OdeToFooDb context)
        {
            //  This method will be called after migrating to the latest version.
            context.Restaurants.AddOrUpdate(r => r.Name,
            new Restaurant { Name = "Sab", City = "Baltimore", Country = "USA" },
            new Restaurant { Name = "Great Pub", City = "Chicago", Country = "USA" },
            new Restaurant
            {
                Name = "Smaka",
                City = "LOLLAND",
                Country = "Sweden",
                Review = new List<RestaurantReview>{
                    new RestaurantReview{
                        Rating = 4,
                        Body = "This place is meh"
                    }   
                }
            });
            
            //default the restaurant description if none entered
            foreach(Restaurant r in context.Restaurants){
                if (string.IsNullOrEmpty(r.Description))
                {
                    r.Description = "no description yet for this restaurant";
                }         
                r.Review = new List<RestaurantReview>();
            }
        }
    }
}
